package com.mjh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mjh.pojo.Events;
import com.mjh.pojo.vo.EventsVo;
import com.mjh.service.IEventsService;
import com.mjh.service.impl.EventsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 *
 * 活动 前端控制器
 *
 *
 * @author MJH
 * @since 2021-12-03
 */
@RestController
@RequestMapping("/events")
public class EventsController {


    @Autowired
    private HttpServletRequest request;

    @Autowired
    private IEventsService iEventsService;


    @Autowired
    private EventsServiceImpl eventsService;

    /**
     * 活动查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
   public ResponseEntity<Object> eventsidslt(@PathVariable("id")Integer id){
        EventsVo eventsVo = eventsService.queryEventsByid(id);
        return ResponseEntity.ok(eventsVo);
    }

    /**
     * 活动列表查询
     * @param currentPage  当前页
     * @param pageSize  每页数量
     * @return
     */
    @GetMapping("/eventstopslt")
    public ResponseEntity<Object> eventstopslt(@RequestParam(defaultValue = "1") Integer currentPage,
                                               @RequestParam(defaultValue = "9")  Integer pageSize){
        Page<Events> page = new Page<>(currentPage,pageSize);
        Page<Events> wtzxPage =iEventsService.eventstop(page);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",wtzxPage.getTotal());
        map.put("currentPage",wtzxPage.getCurrent());
        map.put("list",wtzxPage.getRecords());
        return ResponseEntity.ok(map);
    }


}
